//
//  WPBaseViewController.m
//  wobingwoyi
//
//  Created by WGP on 16/9/19.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPBaseViewController.h"

@interface WPBaseViewController ()

@property(nonatomic,strong)UIView *statusBarView;
@property(nonatomic,strong)UIView *navBarView;
@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong)UIButton *backBtn;

@end
@implementation WPBaseViewController

-(void)viewDidLoad
{
    [super viewDidLoad];
    
    [self statusBarView];
    [self navBarView];
    [self titleLabel];
    [self backBtn];
}

-(UIView *)statusBarView
{
    if (_statusBarView == nil)
    {
        _statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 20)];
        _statusBarView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:_statusBarView];
        
    }
    return _statusBarView;
}

-(UIView *)navBarView
{
    if (_navBarView == nil)
    {
        _navBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, 44)];
        _navBarView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:_navBarView];
        
        UIImageView *lineView = [UIImageView new];
        lineView.backgroundColor = GLobalLineColor;
        [_navBarView addSubview:lineView];
        
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.left.right.equalTo(_navBarView);
            make.height.mas_equalTo(0.5);
        }];
    }
    return  _navBarView;
}

-(UILabel *)titleLabel
{
    if (_titleLabel == nil)
    {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = RGB_SAME(51);
        _titleLabel.font = [UIFont systemFontOfSize:18];
        _titleLabel.text = self.baseTitle;
        [self.navBarView addSubview:_titleLabel];
        
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self.navBarView);
        }];
    }
    return _titleLabel;
}

-(UIButton *)backBtn
{
    if (_backBtn == nil)
    {
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_backBtn setBackgroundImage:[UIImage imageNamed:@"fanhui"] forState:UIControlStateNormal];
        [_backBtn sizeToFit];
        [_backBtn addTarget:self action:@selector(backBtnDidClick) forControlEvents:UIControlEventTouchDown];
        [self.navBarView addSubview:_backBtn];
        
        [_backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.navBarView);
            make.left.equalTo(self.navBarView).offset(10);
        }];
    }
    return _backBtn;
}

-(void)backBtnDidClick
{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
